extends Node
class_name FileManager

func writeContentToFile(content,path):
	var dir = Directory.new()
	dir.make_dir_recursive(path.get_base_dir())
	
	var file=File.new()
	file.open(path,File.WRITE_READ)
	file.store_string(content)
	file.close()
	
func removeFile(path):
	var dir = Directory.new()
	if dir.file_exists(path):
		dir.remove(path)
	
func renameFile(from,to):
	var dir = Directory.new()
	var err = dir.rename(from,to)
	if err != OK:
		print("Failure!",to)


	
func getFileList(path,skip_hidden):
	var file_name
	var files = []
	var dir = Directory.new()
	var error = dir.open(path)
	if error!=OK:
		print("Can't open "+path+"!")
		return
	dir.list_dir_begin(true,skip_hidden)
	file_name = dir.get_next()
	while file_name!="":
		if dir.current_is_dir():
			var new_path = path.plus_file(file_name)
			files += getFileList(new_path,skip_hidden)
		else:
			var name = path+"/"+file_name
			files.push_back(name)
		file_name = dir.get_next()
	dir.list_dir_end()
	return files
	
